import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.util.Date;


public class MemoryTestClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		MemoryUsage heap =
			ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
		MemoryUsage nonHeap =
			ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
		
		System.out.println(heap.getUsed());
		System.out.println(heap.getCommitted());
		System.out.println(nonHeap.getUsed());
		System.out.println(nonHeap.getCommitted());
		
		// create a number of objects
		
		Date[] aFewDates = new Date[100];
		
		for(Date d : aFewDates)
			d = new Date();
		
		System.out.println("---------------------");
		
		heap =
			ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
		nonHeap =
			ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
		
		System.out.println(heap.getUsed());
		System.out.println(heap.getCommitted());
		System.out.println(nonHeap.getUsed());
		System.out.println(nonHeap.getCommitted());
		
	}

}
